/* -*- mode: c++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- */

#ifndef _LUA_WRAP_H_
#define _LUA_WRAP_H_

#include <setjmp.h>

#include <lua.hpp>

#include <string>
#include <vector>

#define LUA_TYPE_INT            0

#define LUA_TYPE_STR            1

#define LUA_TYPE_NIL            2

class LuaArg {
public:
    int                         _type;

    std::string                 _str;

    int                         _int;

    LuaArg() : _type(LUA_TYPE_NIL)
    {
    }
};

typedef std::vector<LuaArg>     LuaArgs;

class LuaWrap {
public:
    lua_State                  *_L;

    std::string                 _fn;

    jmp_buf                     _jmp;

    LuaWrap() : _L(NULL)
    {
    }

    ~LuaWrap() {
        if (_L) {
            lua_close(_L);
        }
    }

    bool load(const char *fn);

    bool run();

    bool run_script_function(const char *func,
                             LuaArgs&    args,
                             LuaArgs&    rets);
};

#endif /* _LUA_WRAP_H_ */
